package cn.edu.ncut.cs.springboot.petmanagementsystem.Config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.Components;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Swagger配置类
 * 注意：context-path为/api，Swagger UI访问地址为: http://localhost:8080/api/swagger-ui/index.html
 */
@Configuration
public class SwaggerConfig {

    @Bean
    public OpenAPI customOpenAPI() {
        return new OpenAPI()
                .info(new Info()
                        .title("宠物管理系统API文档")
                        .version("1.0.0")
                        .description("宠物管理系统后端接口文档，提供用户认证、宠物管理、商品管理、订单管理等功能\n" +
                                "注意：所有API接口的访问路径都自动包含/api前缀（由context-path配置）\n" +
                                "例如：/auth/login 实际访问路径为 http://localhost:8080/api/auth/login")
                        .contact(new Contact()
                                .name("开发团队")
                                .email("support@petmanagement.com"))
                        .license(new License()
                                .name("Apache 2.0")
                                .url("https://www.apache.org/licenses/LICENSE-2.0.html")))
                .components(new Components()
                        .addSecuritySchemes("bearer-jwt", new SecurityScheme()
                                .type(SecurityScheme.Type.HTTP)
                                .scheme("bearer")
                                .bearerFormat("JWT")
                                .description("请输入JWT Token，格式：Bearer {token}")))
                .addSecurityItem(new SecurityRequirement().addList("bearer-jwt"));
    }
}
